package com.study;

import com.alibaba.druid.pool.DruidDataSource;
import com.study.config.ServerConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class ConfigurationApplication {

    @Bean
    @ConfigurationProperties("datasource")
    public DruidDataSource getDataSource() {
        DruidDataSource ds = new DruidDataSource();
        //ds.setDriverClassName("abc");
        return ds;
    }

    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(ConfigurationApplication.class, args);
        ServerConfig config = run.getBean(ServerConfig.class);
        System.out.println(config);

        DruidDataSource ds = run.getBean(DruidDataSource.class);
        System.out.println(ds.getDriverClassName());
    }

}
